
using System;
using UnityEditor;
using UnityEngine;
using LS.UnityExtensions.Editor;

namespace LS.GameKit.Editor
{
    [CustomEditor(typeof(CommandSender))]
    public class CommandSenderInspector : InspectorBase
    {
        protected SerializedProperty m_CoolDown;
        protected SerializedProperty m_SendChannel;
        protected SerializedProperty m_ReceiverObject;
        protected SerializedProperty m_EventKey;
        protected SerializedProperty m_CommandUnityEvent;
        protected SerializedProperty m_OnSendAudio;
        protected SerializedProperty m_AudioDelay;

        protected override void OnEnable()
        {
            base.OnEnable();
            m_CoolDown = serializedObject.FindProperty("coolDown");
            m_SendChannel = serializedObject.FindProperty("sendChannel");
            m_ReceiverObject = serializedObject.FindProperty("receiverObject");
            m_EventKey = serializedObject.FindProperty("eventKey");
            m_CommandUnityEvent = serializedObject.FindProperty("CommandUnityEvent");
            m_OnSendAudio = serializedObject.FindProperty("onSendAudio");
            m_AudioDelay = serializedObject.FindProperty("audioDelay");
        }

        public override void DrawInspectorItems()
        {
            EditorGUILayout.PropertyField(m_CoolDown);
            EditorGUILayout.PropertyField(m_SendChannel);
            CommandChannel channel = (CommandChannel)(m_SendChannel.enumValueFlag);
            if ((channel & CommandChannel.EventModule) == CommandChannel.EventModule)
                EditorGUILayout.PropertyField(m_EventKey);
            if ((channel & CommandChannel.ReceiverObject) == CommandChannel.ReceiverObject)
                EditorGUILayout.PropertyField(m_ReceiverObject);
            if ((channel & CommandChannel.UnityEvent) == CommandChannel.UnityEvent)
                EditorGUILayout.PropertyField(m_CommandUnityEvent);
            
            EditorGUILayout.Space(15);
            EditorGUILayout.PropertyField(m_OnSendAudio);
            EditorGUILayout.PropertyField(m_AudioDelay);
            m_AudioDelay.floatValue = Mathf.Max(0, m_AudioDelay.floatValue);
        }
    }
}
